package com.yyk.yiliao.ui.login.activity;

import androidx.viewpager.widget.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.orhanobut.hawk.Hawk;
import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.adapter.First_Vp_Adapter;
import com.yyk.yiliao.ui.Main_Activity;
import com.yyk.yiliao.widget.ViewPagerScroller;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 导航页
 */
public class First_Activity extends BaseActivity {

    @BindView(R.id.mFirst_bg)
    RelativeLayout mFirstBg;
    @BindView(R.id.mFirst_vp)
    ViewPager mFirstVp;
    First_Vp_Adapter adapter;
    //Viewpager 数据
    private int[] imgs = {R.mipmap.yyk_yygh, R.mipmap.yyk_lykt, R.mipmap.yyk_zhyf, R.mipmap.yyk_jkgl};
    private List<ImageView> imgList;


    @Override
    public int getLayoutId() {
        return R.layout.activity_first;
    }

    @Override
    public void initView() {
        initToolbar();
        initViewPager();
    }

    private void initToolbar() {
        hidetoolBar();
    }

    @Override
    public void initData() {
        initHawk();
    }

    private void initHawk() {
        Hawk.put("MAIN_ACTIVITY", "0");
        Hawk.put("JumpStart", true);
        Hawk.put("QuanxianStart", true);
    }

    /**
     * 初始化ViewPager
     */
    private void initViewPager() {
        imgList = new ArrayList<>();
        for (int i = 0; i < imgs.length; i++) {
            ImageView img = new ImageView(this);
            img.setImageResource(imgs[i]);
            imgList.add(img);
        }
        ViewPagerScroller viewPagerScroller = new ViewPagerScroller(this);
        viewPagerScroller.initViewPagerScroll(mFirstVp);
        adapter = new First_Vp_Adapter(imgList, this);
        mFirstVp.setAdapter(adapter);
        mFirstVp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                if (position == imgList.size() - 1) {
                    mFirstBg.setVisibility(View.VISIBLE);
                } else {
                    mFirstBg.setVisibility(View.GONE);

                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @OnClick(R.id.mFirst_bg)
    public void onViewClicked() {
        startAct(Main_Activity.class, true);
    }


}
